package com.zyt.springcloudconsumerfeignhystrix;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class SpringCloudConsumerFeignHystrixApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringCloudConsumerFeignHystrixApplication.class, args);
    }

    @RestController
    public class TestController {
        @Autowired
        Client client;

        @RequestMapping(value = "/echo/{str}", method = RequestMethod.GET)
        public String echo(@PathVariable String str) {
            return client.hello(str);
        }
    }

    @FeignClient(value = "spring-cloud-provider",fallback = fallback.class)
    interface Client {
        @GetMapping(value = "/echo/{str}")
        String hello(@PathVariable("str") String str);
    }

    @Component
    public class fallback implements Client{

        @Override
        public String hello(String str) {
            return "启动服务降级";
        }
    }
}
